package team.knowers.tourist.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import team.knowers.tourist.common.convention.result.Result;
import team.knowers.tourist.common.convention.result.Results;
import team.knowers.tourist.dao.entity.BookingDO;
import team.knowers.tourist.dto.req.BookingCreateReqDTO;
import team.knowers.tourist.service.BookingService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class BookingController {
    private final BookingService bookingService;
    /**
     * 创建预订订单
     * @param req
     * @return
     */
    @PutMapping("/api/tourist/createBooking")
    public Result<Integer> createBooking (@RequestBody BookingCreateReqDTO req)
    {
        return Results.success(bookingService.createBooking(req));
    }
    /**
     * 取消预订
     */
    @PostMapping("/api/tourist/cancelBooking")
    public Result<Void> cancelBooking(@RequestParam int bookingId)
    {
        bookingService.cancelBooking(bookingId);
        return Results.success();
    }
    @GetMapping("/api/tourist/viewBooking/{touristId}")
    public Result<List<BookingDO>> viewBooking(@PathVariable int touristId)
    {
        return Results.success(bookingService.viewBooking(touristId));
    }
    @GetMapping("/api/tourist/findBooking/{booking}")
    public Result<BookingDO> findBooking(@PathVariable int booking)
    {
        return Results.success(bookingService.findBooking(booking));
    }
}
